//
//  UIDatetimeControl.m
//  iphoneMobo
//
//  Created by Mac Book-1 on 10-9-9.
//  Copyright 2010 shijiazheng. All rights reserved.
//

#import "UIDatetimeControl.h"
#import "FontFactory.h"
#import "ColorFactory.h"


@implementation UIDatetimeControl

@synthesize idtType;
@synthesize iParentView;

-initWithFrame:(CGRect)aRect
{
	self = [super initWithFrame:aRect];
	if (self)
	{
		self.delegate=self;
	}
	return self;
	
}
//初始化label



//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n" 
															 delegate:self
													cancelButtonTitle:@"取消"
											   destructiveButtonTitle:nil
													otherButtonTitles:@"确定", nil];
	actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
	[actionSheet showInView:iParentView];
    UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
    datePicker.tag = 101;
	datePicker.datePickerMode = UIDatePickerMode(idtType);
    [actionSheet addSubview:datePicker];
	return FALSE;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
	
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
	if (buttonIndex == 0)
	{
		UIDatePicker *datePicker = (UIDatePicker *)[actionSheet viewWithTag:101];
		NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
		switch (idtType) {
			case UIDatePickerModeDate:
				formatter.dateFormat = @"YYYY-MM-dd";
				break;
			case UIDatePickerModeTime:
				formatter.dateFormat = @"HH:mm";
				break;
			case UIDatePickerModeDateAndTime:
				formatter.dateFormat = @"YYYY-MM-dd hh:mm";
				break;
			default:
				formatter.dateFormat = @"YYYY-MM-dd hh:mm";
				break;
		}
		
		NSString *timestamp = [formatter stringFromDate:datePicker.date];
		//显示时间的变量
		[self setText:timestamp];
	}
    [actionSheet release];
}

-(void)dealloc
{
	[super dealloc];
}
@end
